<title>系统设置</title>

<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="home/info">主页</a>
        <a><cite>系统管理</cite></a>
        <a><cite>系统设置</cite></a>
    </div>
</div>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-header">系统设置</div>
        <div class="layui-card-body" style="padding: 15px;">
            <script type="text/html" template lay-url="/api/admin/system/setting/get" lay-data="{name: 'setting'}" lay-done="layui.data.done(d)">
            <form class="layui-form" action="" lay-filter="component-form-group">
                <div class="layui-form-item">
                    <label class="layui-form-label">应用名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="title" value="{{ d.data.data.title || '' }}" lay-verify="title" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">应用网址</label>
                    <div class="layui-input-block">
                        <input type="text" name="url" value="{{ d.data.data.url || '' }}" lay-verify="required" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">支付方式</label>
                    <div class="layui-input-block">
                        <input type="checkbox" name="pay_type[]" value="wechat" title="微信" {{ layui.$.inArray('wechat',d.data.data.pay_type) < 0 || 'checked' }}>
                        <input type="checkbox" name="pay_type[]" value="alipay" title="支付宝" {{ layui.$.inArray('alipay',d.data.data.pay_type) < 0 || 'checked' }}>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">区域选择</label>
                    <div class="layui-input-block">
                        <div id="form-region-control"></div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"></label>
                    <div class="layui-input-inline">
                        <button class="layui-btn" lay-submit="" lay-filter="system-setting-save">保存</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
            </script>
        </div>
    </div>
</div>

<script>

    layui.data.done = function (d) {

        layui.use(['admin', 'form', 'regionCheckBox'], function () {
            const $ = layui.$
                , admin = layui.admin
                , element = layui.element
                , layer = layui.layer
                , form = layui.form
                , region = layui.regionCheckBox;

            form.render(null, 'component-form-group');

            /* 自定义验证规则 */
            form.verify({
                title: function (value) {
                    if (value.length < 5) {
                        return '标题至少得5个字符啊';
                    }
                }
            });

            //执行实例
            region.render({
                elem: '#form-region-control',
                name: 'area[]', //input name
                value: d.data.data.area || [], //赋初始值
                width: '550px', //默认550px
                border: true, //默认true
                ready: function () { //初始化完成时执行

                },
                change: function (result) { //点击复选框时执行
                    console.log(result.value);
                }
            });

            /* 监听提交 */
            form.on('submit(system-setting-save)', function (data) {
                admin.req({
                    url: '/api/admin/system/setting/save'
                    , data: layui.$.extend(data.field,{name:'setting'})
                    , done: function (res) {

                        layer.msg('保存成功');
                    }
                });

                return false;
            });
        });
    }
</script>